package com.black.cat.jvm.classpath;

import com.black.cat.jvm.classpath.impl.CompositeEntry;
import com.black.cat.jvm.classpath.impl.DirEntry;
import com.black.cat.jvm.classpath.impl.WildcardEntry;
import com.black.cat.jvm.classpath.impl.ZipEntry;

import java.io.File;

/**
 * @Author blackcat
 * @create 2021/8/11 14:29
 * @version: 1.0
 * @description:
 */
public class EntryFactory {

    public static Entry create(String path) {
        //组合多种形式      UNIX下<code>':'</code>，WIN 下<code>';'</code>
        if (path.contains(File.pathSeparator)) {
            return new CompositeEntry(path);
        }

        //通配符
        if (path.endsWith("*")) {
            return new WildcardEntry(path);
        }

        //jar或zip
        if (path.endsWith(".jar") || path.endsWith(".JAR") ||
                path.endsWith(".zip") || path.endsWith(".ZIP")) {
            return new ZipEntry(path);
        }
        //目录形式
        return new DirEntry(path);
    }
}
